package com.jhoncy.myproject.system.ctrl;

import com.jhoncy.myproject.system.entity.SysRole;
import com.jhoncy.myproject.system.service.SysRoleService;
import com.jhoncy.myproject.common.dto.RestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色
 * @author zhuangqi
 * @@date 2017/3/14.
 */
@RestController
@RequestMapping(value = "/sys/role")
public class SysRoleCtrl {

    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 所用角色列表
     * @return
     */
    @GetMapping
    public RestResponse<List<SysRole>> listRole() {
        RestResponse<List<SysRole>> response = new RestResponse<>();
        response.setData(sysRoleService.listRole());
        return response;
    }

    /**
     * 增加角色
     * @param sysRole
     * @return
     */
    @PostMapping
    public RestResponse saveRole(@RequestBody SysRole sysRole) {
        RestResponse response = new RestResponse();
        sysRoleService.saveRole(sysRole);
        response.setMessage("新增角色成功!");
        return response;
    }

    /**
     * 用户增加角色
     * @param userId 用户ID
     * @param roleId 角色ID
     * @return
     */
    @PostMapping(value = "/userid/{userId}/roleid/{roleId}")
    public RestResponse saveUserRole(@PathVariable String userId, @PathVariable String roleId) {
        RestResponse response = new RestResponse();
        sysRoleService.saveUserRole(userId,roleId);
        response.setMessage("用户设置角色成功!");
        return response;
    }
}
